package com.scarecrow.olga.util.logging {
	/**
	 * ...
	 * @author Santiago.J.Elizalde
	 */
	public class Logger {
		
		static public const LOG_LEVEL_INFO:String = "[INFO]";
		static public const LOG_LEVEL_DEBUG:String = "[DEBUG]";
		static public const LOG_LEVEL_WARN:String = "[WARN]";
		static public const LOG_LEVEL_ERROR:String = "[ERROR]";
		
		static public const LOG_LEVEL_SPECIAL:String = "[SPECIAL]";
		
		static public const LOG_LEVELS:Array = [LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_WARN, LOG_LEVEL_ERROR];
		
		private static var logLevel:int = 0;
		private static var fullLog:Vector.<Log>;
		
		public function Logger() {
			
		}
		
		public static function log(message:String, level:String = LOG_LEVEL_INFO):void {
			if (!fullLog) fullLog = new Vector.<Log>();
			
			fullLog.push(new Log(message, level));
			if (level == LOG_LEVEL_SPECIAL) {
				print(message);
				return;
			}
			if (LOG_LEVELS.indexOf(level) >= logLevel) {
				print(level + " - " + message);
			}
		}
		
		public static function set loggingLevel(level:String):void {
			if (level == LOG_LEVEL_SPECIAL) return;
			logLevel = LOG_LEVELS.indexOf(level);
		}
		
		public static function dumpAll():void {
			dumpAboveLevel(LOG_LEVELS[0]);
		}
		
		public static function dumpAboveLevel(level:String):void {
			
			var levelIndex:uint = LOG_LEVELS.indexOf(level);
			
			for each (var logRegistry:Log in fullLog) {
				
				for (var i:int = levelIndex; i < LOG_LEVELS.length; i++) {
					
					if (logRegistry.level == LOG_LEVELS[i]) {
						if (LOG_LEVELS[i] == LOG_LEVEL_SPECIAL) {
							print(logRegistry.message);
						} else {
							print(level + " - " + logRegistry.message);
						}
					}
				}
			}
		}
		
		public static function dumpSingleLevel(level:String):void {
			
			for each (var logRegistry:Log in fullLog) {
				if(logRegistry.level == level) print(level + " - " + logRegistry.message);
			}
		}
		
		public static function clearLog():void {
			fullLog = new Vector.<Log>();
		}
		
		private static function print(message:String):void {
			trace(message);
		}
	}
}
internal class Log {
	
	public var message:String;
	public var level:String;
	
	public function Log(msg:String, lvl:String) {
		message = msg;
		level = lvl;
	}
}